﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Asteroids
{
    class Player : Ship
    {
        public int level;

        public int exp
        {
            get { return m_exp; }
            set
            {
                m_exp = value;
                if (m_exp >= 100)
                    LevelUp();
            }
        }

        public override Boolean exploder
        {
            get { return m_exploder; }
            set
            {
                if (value)
                    m_sprite = new AnimatedSprite(Game1.shipModels[m_model + 1].texture, 0, 64, 64, 64, 10);
                else
                    m_sprite = new AnimatedSprite(Game1.shipModels[m_model].texture, 0, 64, 64, 64, 10);

                m_exploder = value;
            }

        }

        public Player(int mod, Vector2 pos, Vector2 vel)
            : base(mod, pos, vel) 
        {
            gold = 0;
            m_exp = 0;
            m_sprite = new AnimatedSprite(Game1.shipModels[mod].texture, 0, 64, 64, 64, 10);
            touched = true;
        }

        private void LevelUp()
        {
            m_exp -= 100;
            level++;
            health = maxHealth;
            Game1.playerLevelUps++;
        }

        public void updateStats()
        {
            maxHealth = Game1.shipModels[m_model].health + upgrades[Game1.HEALTH].level * 25;
            m_maxThrust = Game1.shipModels[m_model].maxSpeed + upgrades[Game1.SPEED].level;
            m_mass = Game1.shipModels[m_model].mass + upgrades[Game1.MASS].level * 0.1f;
            m_accelFactor = Game1.shipModels[m_model].accelFactor + upgrades[Game1.ACCEL].level * 0.05f;
        }

        public override void Draw(SpriteBatch sb)
        {
            m_sprite.Draw(sb, position, centerPosition, rotation % (float)(Math.PI * 2));
        }
    }
}
